#ifndef MODALITYPROPERTY_H
#define MODALITYPROPERTY_H

#include <QList>
#include <QString>
#include <QXmlStreamReader>
#include "dcmtk/dcmdata/dctagkey.h"


#define DcmPrivateGroup      0x0021
#define DCM_Pri_CursorX      DcmTagKey(DcmPrivateGroup, 0x0001)
#define DCM_Pri_CursorY      DcmTagKey(DcmPrivateGroup, 0x0002)
#define DCM_Pri_PixelValue   DcmTagKey(DcmPrivateGroup, 0x0003)
#define DCM_Pri_ZoomFactor   DcmTagKey(DcmPrivateGroup, 0x0010)
#define DCM_Pri_WindowCenter DcmTagKey(DcmPrivateGroup, 0x0020)
#define DCM_Pri_WindowWidth  DcmTagKey(DcmPrivateGroup, 0x0021)

typedef struct AnnoItem {
    QString text;
    QList<DcmTagKey> keys;
} AnnoItem;

typedef struct AnnoItemGroup {
    QString pos;
    QList<AnnoItem*> items;
    AnnoItemGroup() {}
    ~AnnoItemGroup() { qDeleteAll(items); }
private:
    Q_DISABLE_COPY(AnnoItemGroup)
} AnnoItemGroup;

typedef struct ModalityPref {
    double adjustFactor;
    double zoomFactor;
    double zoomMax;
    double zoomMin;
    double magnifierInc;
    double magnifierMax;
    double magnifierMin;
    ModalityPref():adjustFactor(16.0),zoomFactor(0.02),zoomMax(32.0),
        zoomMin(0.05),magnifierInc(1.0),magnifierMax(32.0),magnifierMin(2.0){}
} ModalityPref;

typedef struct ModalityProp {
    QString name;
    QList<AnnoItemGroup*> groups;
    ModalityPref pref;
    ModalityProp() {}
    ~ModalityProp() { qDeleteAll(groups); }
private:
    Q_DISABLE_COPY(ModalityProp)
} ModalityProp;


class ModalityProperty
{
public:
    ModalityProperty();
    ~ModalityProperty() { qDeleteAll(props); }

    const ModalityProp *getModalityProp(const QString &modality) const;

    bool isNormal() const { return xml.error() == QXmlStreamReader::NoError; }
    QString errorStr() const {
        return QObject::tr("%1\nLine %2, column %3")
                .arg(xml.errorString())
                .arg(xml.lineNumber())
                .arg(xml.columnNumber());
    }

private:
    void readProperty();
    void readModality(ModalityProp &m);
    void readPref(ModalityPref &p);
    void readAnnoGroup(AnnoItemGroup &g);

    QXmlStreamReader xml;
    QList<ModalityProp*> props;
    Q_DISABLE_COPY(ModalityProperty)
};

#endif // MODALITYPROPERTY_H
